package com.algorithm.hqy;

import com.altorithm.QuickSort;

/**
 * @Classname InterpolationSearches
 * @Date 2019/9/29 9:37
 * @auther by hqy
 */
public class InterpolationSearches {

    public static int searches(int[] array, int findValue) {

        return searches(array, 0, array.length - 1, findValue);
    }


    public static int searches(int[] array, int low, int high, int findValue) {
        if (low < high) {
            int mid = low + (high - low) * (findValue - array[low]) / (array[high] - array[low]);
            if (array[mid] > findValue) {
                low = mid + 1;
                return searches(array, low, high, findValue);
            } else if (array[mid] < findValue) {
                high = mid - 1;
                return searches(array, low, high, findValue);
            } else {
                return mid;
            }
        }

        return -1;
    }

}
